package com.server.server_a10.controller.heatingSystem;

import com.server.server_a10.entity.Inform;
import com.server.server_a10.entity.heatingSystem.HeatingEquipment;
import com.server.server_a10.mapper.HeaterMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api("前后交互的测试用例")
public class HeaterHandle {
    @Autowired
    HeaterMapper heaterMapper;

    @GetMapping(value = "/heatInf")
    @ApiOperation("这个接口是供暖设备的测试接口，入参为设备id，回参为设备信息，" +
            "目前不论id为多少，只要传了id就会返回信息")
    public HeatingEquipment getOneHeatingDemo(String id){
        return new HeatingEquipment(10001L,true,18,1,2);
    }

    @PostMapping(value = "/getHeatersByRoomId")
    public Inform getHeatersByRoomId(@RequestBody Map<String,Object> request){
        Inform inform = new Inform();
        int id = (int) request.get("id");

        List<HeatingEquipment> heatingEquipments = heaterMapper.getHeaterByRoomId(id);

        if (heatingEquipments.isEmpty()){
            inform.setCode(100);
            inform.setMsg("这个房间没有空调，夏天很热，冬天很冷");
        }else {
            inform.setCode(200);
            inform.setData(heatingEquipments);
            inform.setMsg("空调信息加载成功！");
        }

        return inform;
    }

}
